﻿using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using LunaticShade;
using SenseTimeTracker.Misc;
using StedySoft.SenseSDK;

namespace SenseTimeTracker.Main
{
	public abstract class SliderPanel
	{
		protected SenseListControl senseListControl;
		protected MenuItem menuItem;
		protected ContextMenu contextMenu;
		protected SenseTimeTrackerForm ownedForm;
		private MemoryStream smallIconMemoryStream;
		private Image largeIconImage;
		private Imaging.IImage largeIconImagingImage;
		private static Imaging.IImagingFactory factory = Imaging.CreateFactory();

		public abstract string Name { get; }

		public MemoryStream SmallIcon
		{
			get { return smallIconMemoryStream; }
		}

		public Image LargeIcon
		{
			get { return largeIconImage; }
		}

		public Imaging.IImage LargeImage
		{
			get { return largeIconImagingImage; }
		}


		public MenuItem Menu
		{
			get { return menuItem; }
		}

		public ContextMenu ContextMenu
		{
			get { return contextMenu; }
		}

		public SliderPanel(SenseTimeTrackerForm form, string smallIconName, string largeIconName)
		{
			ownedForm = form;

			Assembly assembly = Assembly.GetExecutingAssembly();

			smallIconMemoryStream = (MemoryStream)assembly.GetManifestResourceStream("SenseTimeTracker.Resources." + smallIconName);
			largeIconImage = new Bitmap(assembly.GetManifestResourceStream("SenseTimeTracker.Resources." + largeIconName));
			largeIconImagingImage = Imaging.LoadImageFromStream((MemoryStream)assembly.GetManifestResourceStream("SenseTimeTracker.Resources." + largeIconName), factory);
		}

		public void senseListCtrl_OnHideItemChildren(SenseListControl.ISenseListItem Sender)
		{
			Persistance.Instance.Serialize();
			Bind(senseListControl);
		}

		public void senseListCtrl_OnShowItemChildren(SenseListControl.ISenseListItem Sender)
		{
			BindFilter();
		}

		public virtual void BindFilter()
		{
		}

		public virtual void Bind(SenseListControl senseListControl)
		{
			this.senseListControl = senseListControl;
			senseListControl.Clear();
		}
	}
}
